package com.hibernate.persistence.lifecycle;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class UpdateEntity {

	private static SessionFactory factory = new Configuration().configure().buildSessionFactory();
	private static Session session1;

	public static void main(String[] args) {
		session1 = factory.openSession();
		System.out.println("session1 Before Get=" + session1.toString());
		Message msg1 = (Message) session1.get(Message.class, 3);
		System.out.println("msg1=" + msg1);
		System.out.println("session1 After Get=" + session1.toString());
		msg1.setMessageText(msg1.getMessageText() + "changed");
		System.out.println("session1 After Change msgText=" + session1.toString());
		
		session1.beginTransaction();
		session1.update(msg1);
		session1.getTransaction().commit();
		session1.close();
		
		session1 = factory.openSession();
		msg1 = (Message) session1.get(Message.class, 3);
		System.out.println("msg1=" + msg1);
		session1.close();
		
		
		
	}
}
